package com.team.weigou.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.team.weigou.R;
import com.team.weigou.bean.HomeDataEntity;

import java.util.ArrayList;

public class HomePtrStaggerAdapter extends MyAdapter<HomeDataEntity> {
    private BitmapUtils bitmapUtils;

    public HomePtrStaggerAdapter(ArrayList<HomeDataEntity> list, Context context, BitmapUtils bitmapUtils) {
        super(context,list);
        this.bitmapUtils = bitmapUtils;
    }

    @Override
    public View creatView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_home_layout, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.name.setText(list.get(position).getProduct().getName());
        holder.price.setText("￥" + list.get(position).getProduct().getPrice());
        holder.value.setText("￥" + list.get(position).getProduct().getValue());

        Animation animation= AnimationUtils.loadAnimation(context, R.anim.show_grid_item);
        holder.imageId.startAnimation(animation);
        bitmapUtils.display(holder.imageId, list.get(position).getProduct().getImageId());
        return convertView;
    }

    private static class ViewHolder {
        ImageView imageId;
        TextView name, price, value;

        public ViewHolder(View itemView) {
            imageId = (ImageView) itemView.findViewById(R.id.imageId);
            name = (TextView) itemView.findViewById(R.id.name);
            price = (TextView) itemView.findViewById(R.id.price);
            value = (TextView) itemView.findViewById(R.id.value);
            value.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            itemView.setTag(this);
        }
    }

}
